package com.lixuwei.study.tcc.order.service;

import com.lixuwei.study.tcc.order.dao.OrderDao;
import com.lixuwei.study.tcc.order.entity.Order;
import com.lixuwei.study.tcc.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class OrderService {

    @Autowired
    private UserService userService;

    @Autowired
    private OrderDao orderDao;

    @Transactional
    public Object createOrder(Order order) {
        orderDao.saveOrder(order);
        return order.getId();
    }

    @Transactional
    public void payOrderByPoints(Long orderId) {
        Order order = orderDao.getById(orderId);
        if (order == null) {
            throw new RuntimeException("not found order, order id is" + orderId);
        }
        order.setPayStatus(1);
        orderDao.updateOrderPaying(order);
    }
}
